﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Bidder_CompanyGMPAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void BtnSave_Click(object sender, EventArgs e)
    {
        string AccountId, GMPCode, GMPSatrDate, GMPEndDate, GMPRange;
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCompany);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumComapanyRG);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {


            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            if (_Account != null)
            {

                AccountId = SysFun.IsSQL(SysFun.ToTrim(_Account.AccountId));
                GMPCode = SysFun.IsSQL(SysFun.ToTrim(txtGmpCode.Text));
                GMPEndDate = SysFun.IsSQL(SysFun.ToTrim(SysFun.ToDateTime(txtGmpEndDate.Text).ToString()));
                GMPRange = SysFun.IsSQL(SysFun.ToTrim(txtGmpRange.Text));
                GMPSatrDate = SysFun.IsSQL(SysFun.ToTrim(SysFun.ToDateTime(txtGmpStarDate.Text).ToString()));

                int rowCun = 0;
                string sql = "select count(id) as cun from companygmp where gmpcode='" + GMPCode + "' and  accountid=" + AccountId;
                Db db1 = new Db();
                System.Data.IDataReader dr;
                dr = db1.DataReader(sql);
                if (dr.Read())
                {
                    rowCun = SysFun.ToInt(dr["cun"]);
                }
                dr.Close();
                dr.Dispose();
                db1.Close();
                if (rowCun > 0)
                {
                    Response.Write("<script language=JavaScript>alert('该GMP在数据库中已经存在！！！');</script>");
                    return;
                }
                else
                {
                    string strSql = "insert into  companygmp (accountid,gmpcode,gmpstardate,gmpenddate,gmprange) values('"
                        + AccountId + "','" + GMPCode + "','" + GMPSatrDate + "','" + GMPEndDate + "','" + GMPRange + "')";
                    Db db = new Db();
                    db.Command(strSql);
                    db.Close();
                    Response.Write("<script>alert('保存成功！！！');</script>");
                    // HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                    HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "插入", "companygmp", strSql, "../Bidder/CompanyGMPAdd.aspx");
                }

            }
            else
            {
                Response.Write("<script language=JavaScript>alert('您无权添加企业GMP信息！！！');</script>");
            }
            Response.Write("<script>window.opener.location.reload();window.close();</script>");
        }
    }
}
